
import os

def read_file(fileName):
	fin = open(fileName,'r')
	val = fin.read().decode('utf8')
	fin.close()
	return val

def read_basic_html(fileName, replace_map):
	if not os.path.exists(fileName): return ''


	top_stuff = read_file('html/common_top.html')
	analytics = read_file('html/analytics_track.html')
	bottom = read_file('html/bottom_content.html')
	val = read_file(fileName)

	val = val.replace('<!-- analytics -->', analytics)
	val = val.replace('<!-- bottom content -->', bottom)
	val = val.replace('<!-- common top -->', top_stuff)

	for i, j in replace_map.items(): val = val.replace(i, j)

	return val

def redirect_page(page_name):
	redir = '<html>'
	redir += '<head>'
	redir += 	'<meta http-equiv="Refresh" content="0;url=/' + page_name + '">'
	redir += '</head>'
	redir += '<body>'
	redir += '</body>'
	redir += '</html>'
	return redir

